(function() {
    $("#cardset-form").handleForm({
        isSubmit: true,
        closest: ".form-group",
        rules: {
            money: {
                required: true,
            },
            starttime: {
                required: true,
            },
            endtime: {
                required: true,
            },
            usemoney: {
                required: true,
            },
            cardnum: {
                required: true,
            },
            cardname:{
                required: true,
            }
        },
        messages: {
            money: {
                required: "请输入卡券金额"
            },
            starttime: {
                required: "请输入有效开始时间",
            },
            endtime: {
                required: "请输入有效期结束时间"
            },
            usemoney: {
                required: "请输入金额"
            },
            cardnum: {
                required: "请输入生成数量"
            },
            cardname: {
                required: "请输入卡券名称"
            }
        }
    });


    var actImgObj = WebUploader.create({
        auto: false,
        swf: 'Uploader.swf',
        fileSingleSizeLimit: 1024 * 1024 * 2,
        server: serverurl,
        pick: '#image-handle',
        duplicate: true,
        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/*',
        },
    });

    actImgObj.on('fileQueued', function(file) {
        actImgObj.upload();
    });

    actImgObj.on('error', function(code) {
        switch (code) {
            case 'F_EXCEED_SIZE':
                last_gritter = $.gritter.add({
                    title: '上传失败',
                    text: '图片大小不能超过2M',
                    class_name: 'gritter-error gritter-center'
                });
                break;
            case 'Q_EXCEED_NUM_LIMIT':
                last_gritter = $.gritter.add({
                    title: '上传失败',
                    text: '超过文件上传数连限制',
                    class_name: 'gritter-error gritter-center'
                });
                break;
        }
    })

    /*上传成功**/
    actImgObj.on('uploadSuccess', function(file, data) {
        if (data.code == 1) {
            $("#cardPic").val(data['url']);
            $("#img-act").attr('src', data['url']);
        } else {
            // console.log({ status: data.code, msg: data.msg });
        }
    });

    actImgObj.reset();
}())